<?php
/**
 * User: zibuyu
 * Date: 2015/7/31
 * link    http://www.ibuyu.cn
 */
class category{
    function getList($id=0){
        $sql='select * from __category where `parent_id`='.$id.'  order by sort asc';
        return db::get_all($sql);
    }
    static function getListTree($id = 0, $pre = '-') {
        $result = array();
        //$blank = '&nbsp;&nbsp;';'├─'
        $sql = 'select * from __category where `parent_id`=' . $id .' order by sort asc';
        $res = db::_query($sql);
        while ($row = db::_object($res)) {
            if ($row->parent_id > 0) $row->cat_name = $pre . $row->cat_name;
            $result[] = $row;
            $z = self::getListTree($row->cat_id, $pre.$pre);
            $result = array_merge($result, $z);
        }
        return $result;
    }
    static function getCat($id){
        $sql='select * from __category where `cat_id`='.$id.' order by sort asc';
        return db::_object($sql);
    }
    static function getCatExtend($id,$cols = '*'){
        if($id)$where=' where e.goods_id='.$id;
        $sql='select '.$cols.' from __category c left join __category_extend e on c.cat_id=e.category_id '.$where.' order by c.sort asc';
        return db::get_all($sql);
    }
}